<?php

use think\facade\Route;
use Symfony\Component\Finder\Finder;

Route::group('api', function () {
    // 系统初始化
    Route::get('init', 'api.Index/init');
    Route::get('test', 'api.Index/test');
    // 自定义页面
    Route::get('page/:id', 'api.Index/page');
    // 问题反馈
    Route::post('feedback', 'api.Index/feedback');
    Route::post('sendSms', 'api.index/sendSms');
    Route::get('notification/[:type]', 'api.index/notification');

    // 同步前端路由
    Route::post('pageSync', 'api.index/pageSync');
    Route::get('goods/goods/ids', 'api.goods.Goods/ids')->name('api.goods.goods.ids');
    Route::get('goods/goods/activity', 'api.goods.Goods/activity')->name('api.goods.goods.activity');
    Route::get('goods/goods/activityList', 'api.goods.Goods/activityList')->name('api.goods.goods.activityList');
    Route::resource('goods/goods', 'api.goods.Goods');

    Route::get('goods/comment/getType/:goods_id', 'api.goods.Comment/getType')->name('api.goods.comment.getType');
    Route::get('goods/comment/:goods_id', 'api.goods.Comment/list')->name('api.goods.comment.list');

    Route::get('app/scoreShop', 'api.app.ScoreShop/list')->name('api.app.scoreShop.list');
    Route::get('app/scoreShop/ids', 'api.app.ScoreShop/ids')->name('api.app.scoreShop.ids');
    Route::get('app/scoreShop/:id', 'api.app.ScoreShop/detail')->name('api.app.scoreShop.detail');

    // 领券中心
    Route::get('coupon/listByGoods/:goods_id', 'api.Coupon/listByGoods');
    Route::get('coupon/:id', 'api.Coupon/detail');
    Route::get('coupon', 'api.Coupon/list');

    Route::get('pay/alipay', 'api.Pay/alipay')->name('api.pay.alipay');
    Route::post('pay/notify/:payment/:platform', 'api.Pay/notify')->name('api.pay.notify');
    Route::post('pay/notifyRefund/:payment/:platform', 'api.Pay/notifyRefund')->name('api.pay.notifyRefund');

    Route::get('category', 'api.Category/list')->name('api.category.list');

    // 获取拼团未支付订单
    Route::get('order/order/unpaidGrouponOrder', 'api.order.Order/unpaidGrouponOrder')->name('api.order.order.unpaidGrouponOrder');

    // 物流推送接口，不需登录
    Route::any('order/express/push', 'api.order.Express/push')->name('api.order.Express.push');

    Route::get('activity/groupon/:id', 'api.activity.Groupon/detail')->name('api.activity.Groupon/detail')->pattern(['id' => '\d+']);
    Route::get('activity/groupon', 'api.activity.Groupon/list')->name('api.activity.Groupon/list');

    // 活动详情
    Route::get('activity/activity/:id', 'api.activity.Activity/detail')->name('api.activity.Activity/detail');

    Route::group(function () {
        // 必须登录路由

        // 添加分享记录
        Route::post('share/add', 'api.Share/add');
        // 分享记录
        Route::get('share/list', 'api.Share/list');

        Route::get('unifiedToken', 'api.Index/unifiedToken')->name('api.index.unifiedToken');

        Route::post('coupon/get/:id', 'api.Coupon/get');

        // 订单相关
        Route::get('order/order', 'api.order.Order/list')->name('api.order.order.list');
        Route::post('order/order/coupons', 'api.order.Order/coupons')->name('api.order.order.coupons');
        Route::post('order/order/calc', 'api.order.Order/calc')->name('api.order.order.calc');
        Route::post('order/order/create', 'api.order.Order/create')->name('api.order.order.create');
        Route::put('order/order/cancel/:id', 'api.order.Order/cancel')->name('api.order.order.cancel');
        Route::put('order/order/applyRefund/:id', 'api.order.Order/applyRefund')->name('api.order.order.applyRefund');
        Route::put('order/order/confirm/:id', 'api.order.Order/confirm')->name('api.order.order.confirm');
        Route::post('order/order/comment/:id', 'api.order.Order/comment')->name('api.order.order.comment');
        Route::delete('order/order/:id', 'api.order.Order/delete')->name('api.order.order.delete');
        Route::get('order/order/:id', 'api.order.Order/detail')->name('api.order.order.detail');
        Route::get('order/order/itemDetail/:id/:item_id', 'api.order.Order/itemDetail')->name('api.order.order.itemDetail');

        Route::get('order/express/:order_id', 'api.order.Express/list')->name('api.order.Express.list');
        Route::get('order/express/:id/:order_id', 'api.order.Express/detail')->name('api.order.Express.detail');
        // 售后单
        Route::put('order/aftersale/cancel/:id', 'api.order.Aftersale/cancel')->name('api.order.Aftersale.cancel');
        Route::resource('order/aftersale', 'api.order.Aftersale');

        // 订单发票
        Route::get('order/invoice', 'api.order.Invoice/list')->name('api.order.Invoice.list');
        Route::get('order/invoice/:id', 'api.order.Invoice/detail')->name('api.order.Invoice.detail');
        Route::put('order/invoice/:id', 'api.order.Invoice/cancel')->name('api.order.Invoice.cancel');

        Route::get('trade/order/rechargeRules', 'api.trade.Order/rechargeRules')->name('api.trade.order.rechargeRules');
        Route::get('trade/order', 'api.trade.Order/list')->name('api.trade.order.list');
        Route::post('trade/order/recharge', 'api.trade.Order/recharge')->name('api.trade.order.recharge');
        Route::get('trade/order/:id', 'api.trade.Order/detail')->name('api.trade.order.detail');


        // 我的购物车
        Route::get('cart', 'api.Cart/list')->name('api.cart.list');
        Route::post('cart', 'api.Cart/update')->name('api.cart.update');
        Route::delete('cart/:id', 'api.Cart/delete')->name('api.cart.delete');

        Route::get('activity/signin', 'api.activity.Signin/list')->name('api.activity.signin.list');
        Route::post('activity/signin', 'api.activity.Signin/signin')->name('api.activity.signin.signin');
        Route::post('activity/signin/replenish', 'api.activity.Signin/replenish')->name('api.activity.signin.replenish');

        // 我的拼团列表
        Route::get('activity/groupon/myGroupons', 'api.activity.Groupon/myGroupons')->name('api.activity.Groupon/myGroupons');

        // 支付
        Route::post('pay/prepay', 'api.Pay/prepay')->name('api.pay.prepay');
    })->middleware('check_login', 'user');


    $finder = new Finder();
    $finder->files()->in(__DIR__ . '/api')->name('*.php');

    foreach ($finder as $file) {
        require $file->getRealPath();
    }
});
